#pragma once
#include "Game.h"

class Player
{
private:
	string name;
	int xPos, yPos;
	deque<char> *queue;

public:

	Player()
	{
		this->name = "";
		this->xPos = 0;
		this->yPos = 0;
	}

	Player(string name, int xPos, int yPos, deque<char> *queue)
	{
		this->name = name;
		this->xPos = xPos;
		this->yPos = yPos;
		this->queue = queue;
	}

	void operator()()
	{
		while (1)
		{
			mutex_cout.lock();
			Position p;
			p.name = this->name;
			p.previousX = this->xPos;
			p.previousY = this->yPos;
			
			if (queue->empty());

			else
			{
				if (queue->back() == 'w' ||	queue->back() == '8')
				{
					if (yPos != 0)
					{
						yPos--;
					}
				}

				else if (queue->back() == 'a' || queue->back() == '4')
				{
					if (xPos != 0)
					{
						xPos--;
					}
				}

				else if (queue->back() == 's' || queue->back() == '5')
				{
					if (yPos != 19)
					{
						yPos++;
					}
				}

				else if (queue->back() == 'd' || queue->back() == '6')
				{
					if (xPos != 19)
					{
						xPos++;
					}
				}			

				queue->pop_back();
			}

			p.xPos = this->xPos;
			p.yPos = this->yPos;
			positioner.push_back(p);

			mutex_cout.unlock();
			this_thread::sleep_for(chrono::milliseconds(100));
		}
	}
	~Player()
	{
	}
};

